<?php
/*
	提现管理
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'会员提现记录'),
	array('op'=>'listhe','title'=>'合并API提现'),
	array('op'=>'listday','title'=>'每日提现统计'),
	array('op'=>'listmonth','title'=>'每月提现统计'),
);
if($_RQ['op']=='list'){	
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(isset($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getslice('core_member_cash',$params,array($pindex,$psize),$total,array(),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=model('core/core')->member_show($item['mid']);
			$fans=pdo_get('core_fans',array('mid'=>$item['mid']),array('wxgid'));
			if($item['member']['from_os']==1){
				$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$fans['wxgid']),'title');
				$item['apptype']='小程序';
			}else{
				$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$fans['wxgid']),'title');
				$item['apptype']='公众号';
			}
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'tip'=>'[温馨提示]：</br>【<red>提示:NO_AUTH产品权限验证失败？</red>】</br>1、站点设置--支付参数--微信支付那边要上传微信支付证书；2、微信商户那边要开启“企业付款到零钱”的权限；','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员','type'=>'member'),
			array('name'=>'apptype','title'=>'来源','type'=>'string'),
			array('name'=>'apptitle','title'=>'所属','type'=>'string'),
			array('name'=>'type','title'=>'提现类型','type'=>'radio','options'=>'type_array'),
			array('name'=>'ordersn','title'=>'提现单号','type'=>'string'),
			array('name'=>'money','title'=>'提现金额','type'=>'string'),
			array('name'=>'service_money','title'=>'提现手续费','type'=>'string'),
			array('name'=>'cash_money','title'=>'预计到账金额','type'=>'string'),
			array('name'=>'status','title'=>'提现状态','type'=>'radio','options'=>'statuss'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'log','title'=>'现金日志'),
			array('type'=>'modal','op'=>'check','title'=>'审核','show'=>array('status'=>0)),
		),'batch'=>array(
			array('type'=>'modal','url'=>'/tixian/checkmore/','title'=>'一键审核提现'),
		)),
		'search'=>array(
			array('type'=>'radio','width'=>15,'title'=>'提现状态','name'=>'status','options'=>'statuss'),
			array('type'=>'radio','width'=>15,'title'=>'提现类型','name'=>'type','options'=>'type_array'),
			array('type'=>'choose','width'=>15,'title'=>'会员id','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
			array('type'=>'time_range','width'=>18,'title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	$return['statuss']=array(
		'0'=>'待审核',
		'1'=>'已打款',
		'2'=>'审核不通过',
	);
	$return['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡','提现余额','api'=>'接口提现');
	exi($return);
}
if($_RQ['op']=='listhe'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 50;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0,'type'=>'api');
	$return['params']=array();
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('core_member_cash',$params,array(),'','id desc');
	$listhe=array();
	if($list){
		foreach($list as $item){
			$item['member']=model('core/core')->member_show($item['mid']);
			$fans=pdo_get('core_fans',array('mid'=>$item['mid']),array('wxgid'));
			if($item['member']['from_os']==1){
				$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$fans['wxgid']),'title');
				$item['apptype']='小程序';
			}else{
				$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$fans['wxgid']),'title');
				$item['apptype']='公众号';
			}
			if(!$listhe[$item['bankcard']]){
				$listhe[$item['bankcard']]=$item;
			}else{
				$listhe[$item['bankcard']]['money'] +=$item['money'];
				$listhe[$item['bankcard']]['service_money'] +=$item['service_money'];
				$listhe[$item['bankcard']]['cash_money'] +=$item['cash_money'];
			}
		}
	}
	$return['list']=$listhe?$listhe:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export2',
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：</br>【<red>提示:NO_AUTH产品权限验证失败？</red>】</br>1、站点设置--支付参数--微信支付那边要上传微信支付证书；2、微信商户那边要开启“企业付款到零钱”的权限；','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员','type'=>'member'),
			array('name'=>'apptype','title'=>'来源','type'=>'string'),
			array('name'=>'apptitle','title'=>'所属','type'=>'string'),
			array('name'=>'type','title'=>'提现类型','type'=>'radio','options'=>'type_array'),
			array('name'=>'ordersn','title'=>'提现单号','type'=>'string'),
			array('name'=>'money','title'=>'提现金额','type'=>'string'),
			array('name'=>'service_money','title'=>'提现手续费','type'=>'string'),
			array('name'=>'cash_money','title'=>'预计到账金额','type'=>'string'),
			array('name'=>'status','title'=>'提现状态','type'=>'radio','options'=>'statuss'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'log','title'=>'现金日志'),
			array('type'=>'modal','op'=>'checkhe','title'=>'审核打款','show'=>array('status'=>0)),
		),'batch'=>array(
			array('type'=>'modal','url'=>'/tixian/checkhemore/','title'=>'一键审核提现'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'title'=>'会员id','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
			array('type'=>'time_range','width'=>18,'title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	$return['statuss']=array(
		'0'=>'待审核',
		'1'=>'已打款',
		'2'=>'审核不通过',
	);
	$return['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡','提现余额','api'=>'接口提现');
	exi($return);
}
if($_RQ['op']=='listday'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$y=$_RQ['y']?:date('Y');
	$m=$_RQ['m']?:date('m');
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	$daynum=date("t",strtotime($y.'-'.$m));
	$list=array();
	for($i=1;$i<=$daynum;$i++){
		$starttime=strtotime($y.'-'.$m.'-'.$i);
		$endtime=$starttime+24*3600;
		$params['createtime between']=array($starttime,$endtime);
		$fee=pdo_getsum('core_member_cash',$params,'money');
		$list[]=array(
			'title'=>$y.'-'.$m.'-'.$i,
			'fee'=>$fee,
		);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'日期','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'y','width'=>15,'title'=>'年份','type'=>'radio','options'=>'ys'),
			array('name'=>'m','width'=>15,'title'=>'月份','type'=>'radio','options'=>'months'),
		)
	);
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'1'=>'1月',
		'2'=>'2月',
		'3'=>'3月',
		'4'=>'4月',
		'5'=>'5月',
		'6'=>'6月',
		'7'=>'7月',
		'8'=>'8月',
		'9'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	exi($return);
}
if($_RQ['op']=='listmonth'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$y=$_RQ['y']?:date('Y');
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	$list=array();
	for($i=1;$i<=12;$i++){
		$starttime=strtotime($y.'-'.$i);
		if($i==12){
			$ny=$y+1;
			$endtime=strtotime($ny.'-01');
		}else{
			$endtime=strtotime($y.'-'.$m+1);
		}
		$params['createtime between']=array($starttime,$endtime);
		$fee=pdo_getsum('core_member_cash',$params,'money');
		$list[]=array(
			'title'=>$y.'-'.$i,
			'fee'=>$fee,
		);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'月份','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'y','width'=>15,'title'=>'年份','type'=>'radio','options'=>'ys'),
		)
	);
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$type=$post['type'];
		$status=intval($post['status']);
		if(!$status){
			exi('请先选择是否审核通过！','error');
		}
		if($status==1){
			if(!$type){
				model('core/member/cash')->pay($id);
			}elseif($type==3){
				//提现到余额
				$money=$item['money'];
				if($item['merchid']){
					model('jy_merch/member')->member_credit($item['merchid'],$item['mid'],'credit2',$money,true,'core','币提现到余额');
				}else{
					model('core/member')->member_credit($item['mid'],'credit2',$money,true,'core','币提现到余额');
				}
				pdo_update('core_member_cash',array('status'=>1),array('id'=>$id));
			}elseif($type=='api'){
				if($this->plugin_exists('jy_huiqi365')){
					$item['money']=$item['cash_money'];
					model('jy_huiqi365/api')->tixian($item);
				}
				pdo_update('core_member_cash',array('status'=>1),array('id'=>$id));
			}else{
				pdo_update('core_member_cash',array('status'=>1),array('id'=>$id));
			}
			exi('打款成功！','','list');
		}else{
			if(!$post['remark']){
				exi('请填写审核不通过原因！','error');
			}
			pdo_update('core_member_cash',array('status'=>2,'remark'=>trim($post['remark'])),array('id'=>$id));
			$credit_type=$item['credit_type']?:2;
			if($credit_type==2){
				$money=$item['money'];
			}else{
				$money=$item['credit_fee'];
			}
			if($item['merchid']){
				$res=model('jy_merch/member')->thaw_credit($item['merchid'],$item['mid'],$money,'会员提现解冻','core',$credit_type);
			}else{
				$res=model('core/member')->thaw_credit($item['mid'],$money,'会员提现解冻','core',$credit_type);
			}
			if($res){
				if($item['merchid']){
					model('jy_merch/member')->member_credit($item['merchid'],$item['mid'],'credit'.$credit_type,$money,true,'core','提现审核失败退回');
				}else{
					model('core/member')->member_credit($item['mid'],'credit'.$credit_type,$money,true,'core','提现审核失败退回');
				}
			}
			exi('操作成功！','','list');
		}
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('core_member_cash',array('id'=>$id));
	if(!$item){
		exi('指定提现申请不存在~','error');
	}
	if($item['status']){
		exi('该提现申请已审核，请勿重复审核~','error');
	}
	
	$return['statuss']=array(
		'1'=>'审核通过并打款',
		'2'=>'审核不通过',
	);
	$return['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡','提现余额','api'=>'接口提现');
	$item['typetitle']=$return['type_array'][$item['type']];
	$member=model('core/core')->member_show($item['mid']);
	$item['wxgid']=pdo_getcolumn('core_fans',array('mid'=>$item['mid']),'wxgid');
	if($member['from_os']==1){
		$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$item['wxgid']),'title')?:'';
	}else{
		$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$item['wxgid']),'title')?:'';
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'tip','title'=>'【温馨提示】：如果打款会员是<red>小程序</red>会员，会显示所属《小程序》，否则可能会打款不成功!默认打款使用的是公众号！'),
			array('name'=>'apptitle','title'=>'所属','type'=>'copy'),
			array('type'=>'copy','name'=>'typetitle','title'=>'提现类型'),
			array('type'=>'copy','name'=>'money','title'=>'提现金额'),
			array('type'=>'copy','name'=>'cash_money','title'=>'真实到账金额'),
			array('type'=>'copy','name'=>'realname','title'=>'姓名','show'=>array('type'=>array(1,2,'api'))),
			array('type'=>'copy','name'=>'alipay','title'=>'支付宝账号','show'=>array('type'=>array(1))),
			array('type'=>'copy','name'=>'bankname','title'=>'所属银行','show'=>array('type'=>array(2,'api'))),
			array('type'=>'copy','name'=>'bankcard','title'=>'银行卡号','show'=>array('type'=>array(2,'api'))),
			array('type'=>'copy','name'=>'mobile','title'=>'手机号','show'=>array('type'=>array(2,'api'))),
			array('type'=>'radio','name'=>'status','title'=>'审核','options'=>'statuss'),
			array('name'=>'remark','title'=>'不通过原因','type'=>'string','show'=>array('status'=>2)),
		),
	);
	$return['wxapps']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
}
if($_RQ['op']=='checkhe'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$type=$post['type'];
		$status=intval($post['status']);
		if(!$status){
			exi('请先选择是否审核通过！','error');
		}
		if($status==1){
			if($type=='api'){
				if($this->plugin_exists('jy_huiqi365')){
					$item['money']=$item['cash_money'];
					model('jy_huiqi365/api')->tixian($item);
				}
				pdo_update('core_member_cash',array('status'=>1),array('bankcard'=>$item['bankcard'],'status'=>0,'type'=>'api','uniacid'=>$_SESSION['uniacid']));
			}else{
				exi('仅支持接口打款！','','list');
			}
			exi('合并打款成功！','','list');
		}else{
			exi('操作成功！','','list');
		}
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('指定提现申请不存在~','error');
	}
	if($item['status']){
		exi('该提现申请已审核，请勿重复审核~','error');
	}
	$item['money']=pdo_getsum('core_member_cash',array('type'=>'api','status'=>0,'bankcard'=>$item['bankcard'],'uniacid'=>$_SESSION['uniacid']),'money');
	$item['service_money']=pdo_getsum('core_member_cash',array('type'=>'api','status'=>0,'bankcard'=>$item['bankcard'],'uniacid'=>$_SESSION['uniacid']),'service_money');
	$item['cash_money']=pdo_getsum('core_member_cash',array('type'=>'api','status'=>0,'bankcard'=>$item['bankcard'],'uniacid'=>$_SESSION['uniacid']),'cash_money');
	$return['statuss']=array(
		'1'=>'审核通过并打款',
		'2'=>'审核不通过',
	);
	$return['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡','提现余额','api'=>'接口提现');
	$item['typetitle']=$return['type_array'][$item['type']];
	$member=model('core/core')->member_show($item['mid']);
	$item['wxgid']=pdo_getcolumn('core_fans',array('mid'=>$item['mid']),'wxgid');
	if($member['from_os']==1){
		$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$item['wxgid']),'title')?:'';
	}else{
		$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$item['wxgid']),'title')?:'';
	}
	$item['status']=1;
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'tip','title'=>'【温馨提示】：如果打款会员是<red>小程序</red>会员，会显示所属《小程序》，否则可能会打款不成功!默认打款使用的是公众号！'),
			array('name'=>'apptitle','title'=>'所属','type'=>'copy'),
			array('type'=>'copy','name'=>'typetitle','title'=>'提现类型'),
			array('type'=>'copy','name'=>'money','title'=>'提现金额'),
			array('type'=>'copy','name'=>'cash_money','title'=>'真实到账金额'),
			array('type'=>'copy','name'=>'realname','title'=>'姓名','show'=>array('type'=>array(1,2,'api'))),
			array('type'=>'copy','name'=>'alipay','title'=>'支付宝账号','show'=>array('type'=>array(1))),
			array('type'=>'copy','name'=>'bankname','title'=>'所属银行','show'=>array('type'=>array(2,'api'))),
			array('type'=>'copy','name'=>'bankcard','title'=>'银行卡号','show'=>array('type'=>array(2,'api'))),
			array('type'=>'copy','name'=>'mobile','title'=>'手机号','show'=>array('type'=>array(2,'api'))),
			//array('type'=>'radio','name'=>'status','title'=>'审核','options'=>'statuss'),
			//array('name'=>'remark','title'=>'不通过原因','type'=>'string','show'=>array('status'=>2)),
		),
	);
	$return['wxapps']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
}
if($_RQ['op']=='checkhemore'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$ids=$post['ids'];
		$status=intval($post['status']);
		if(!$status){
			exi('请先选择是否审核通过！','error');
		}
		foreach($ids as $id){
			$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			if($item['status']){
				exi('有的提现申请已审核，请勿重复审核~','error');
			}
			$type=$item['type'];
			if($status==1){
				if($type=='api'){
					if($this->plugin_exists('jy_huiqi365')){
						$item['money']=$item['cash_money'];
						model('jy_huiqi365/api')->tixian($item);
					}
					pdo_update('core_member_cash',array('status'=>1),array('bankcard'=>$item['bankcard'],'status'=>0,'type'=>'api','uniacid'=>$_SESSION['uniacid']));
				}else{
					exi('仅支持接口打款！','','list');
				}
			}else{
				
			}
		}
		exi('操作成功！','','list');
	}
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择提现申请','error');
	}
	$item=pdo_get('core_member_cash',array('id'=>$ids[0],'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('指定提现申请不存在~','error');
	}
	foreach($ids as $id){
		$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		if($item['status']){
			exi('有的提现申请已审核，请勿重复审核~','error');
		}
	}
	$item['ids']=$ids;
	$return['statuss']=array(
		'1'=>'审核通过并打款',
		'2'=>'审核不通过',
	);
	$return['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡','提现余额','api'=>'接口提现');
	$item['typetitle']=$return['type_array'][$item['type']];
	$member=model('core/core')->member_show($item['mid']);
	$item['wxgid']=pdo_getcolumn('core_fans',array('mid'=>$item['mid']),'wxgid');
	if($member['from_os']==1){
		$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$item['wxgid']),'title')?:'';
	}else{
		$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$item['wxgid']),'title')?:'';
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'tip','title'=>'【温馨提示】：如果打款会员是<red>小程序</red>会员，会显示所属《小程序》，否则可能会打款不成功!默认打款使用的是公众号！'),
			array('name'=>'apptitle','title'=>'所属','type'=>'copy'),
			array('type'=>'radio','name'=>'status','title'=>'审核','options'=>'statuss'),
			array('name'=>'remark','title'=>'不通过原因','type'=>'string','show'=>array('status'=>2)),
		),
	);
	$return['wxapps']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
}
if($_RQ['op']=='checkmore'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$ids=$post['ids'];
		$status=intval($post['status']);
		if(!$status){
			exi('请先选择是否审核通过！','error');
		}
		foreach($ids as $id){
			$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			if($item['status']){
				exi('有的提现申请已审核，请勿重复审核~','error');
			}
			$type=$item['type'];
			if($status==1){
				if(!$type){
					model('core/member/cash')->pay($id);
				}elseif($type==3){
					//提现到余额
					$money=$item['money'];
					if($item['merchid']){
						model('jy_merch/member')->member_credit($item['merchid'],$item['mid'],'credit2',$money,true,'core','币提现到余额');
					}else{
						model('core/member')->member_credit($item['mid'],'credit2',$money,true,'core','币提现到余额');
					}
					pdo_update('core_member_cash',array('status'=>1),array('id'=>$id));
				}elseif($type=='api'){
					if($this->plugin_exists('jy_huiqi365')){
						$item['money']=$item['cash_money'];
						model('jy_huiqi365/api')->tixian($item);
					}
					pdo_update('core_member_cash',array('status'=>1),array('id'=>$id));
				}else{
					pdo_update('core_member_cash',array('status'=>1),array('id'=>$id));
				}
			}else{
				if(!$post['remark']){
					exi('请填写审核不通过原因！','error');
				}
				pdo_update('core_member_cash',array('status'=>2,'remark'=>trim($post['remark'])),array('id'=>$id));
				$credit_type=$item['credit_type']?:2;
				if($credit_type==2){
					$money=$item['money'];
				}else{
					$money=$item['credit_fee'];
				}
				if($item['merchid']){
					$res=model('jy_merch/member')->thaw_credit($item['merchid'],$item['mid'],$money,'会员提现解冻','core',$credit_type);
				}else{
					$res=model('core/member')->thaw_credit($item['mid'],$money,'会员提现解冻','core',$credit_type);
				}
				if($res){
					if($item['merchid']){
						model('jy_merch/member')->member_credit($item['merchid'],$item['mid'],'credit'.$credit_type,$money,true,'core','提现审核失败退回');
					}else{
						model('core/member')->member_credit($item['mid'],'credit'.$credit_type,$money,true,'core','提现审核失败退回');
					}
				}
			}
		}
		exi('操作成功！','','list');
	}
	$ids=trim($_RQ['ids'],';');
	if($ids){
		$ids=explode(';',$ids);
	}else{
		$ids=array();
	}
	if($_RQ['id']){
		$ids[]=$_RQ['id'];
	}
	if(count($ids)==0){
		exi('请先选择提现申请','error');
	}
	$item=pdo_get('core_member_cash',array('id'=>$ids[0],'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('指定提现申请不存在~','error');
	}
	foreach($ids as $id){
		$item=pdo_get('core_member_cash',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		if($item['status']){
			exi('有的提现申请已审核，请勿重复审核~','error');
		}
	}
	$item['ids']=$ids;
	$return['statuss']=array(
		'1'=>'审核通过并打款',
		'2'=>'审核不通过',
	);
	$return['type_array']=array('提现到微信钱包','提现到支付宝','提现到银行卡','提现余额','api'=>'接口提现');
	$item['typetitle']=$return['type_array'][$item['type']];
	$member=model('core/core')->member_show($item['mid']);
	$item['wxgid']=pdo_getcolumn('core_fans',array('mid'=>$item['mid']),'wxgid');
	if($member['from_os']==1){
		$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$item['wxgid']),'title')?:'';
	}else{
		$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$item['wxgid']),'title')?:'';
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'tip','title'=>'【温馨提示】：如果打款会员是<red>小程序</red>会员，会显示所属《小程序》，否则可能会打款不成功!默认打款使用的是公众号！'),
			array('name'=>'apptitle','title'=>'所属','type'=>'copy'),
			array('type'=>'radio','name'=>'status','title'=>'审核','options'=>'statuss'),
			array('name'=>'remark','title'=>'不通过原因','type'=>'string','show'=>array('status'=>2)),
		),
	);
	$return['wxapps']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
}
if($_RQ['op']=='log'){
	$return['types']=array(
		'1'=>'积分',
		'2'=>'余额'
	);
	$return['adds']=array(
		'0'=>'消费',
		'1'=>'获得',
		'2'=>'提现',
	);
	$return['types2']=array(
		array('id'=>1,'title'=>'积分'),
		array('id'=>2,'title'=>'余额'),
	);
	$return['adds2']=array(
		array('id'=>0,'title'=>'消费'),
		array('id'=>1,'title'=>'获得'),
		array('id'=>2,'title'=>'提现'),
	);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//exi('!!'.$_RQ['id'],'error');
	$params['mid']=pdo_getcolumn('core_member_cash',array('id'=>$_RQ['id']),'mid');
	$return['params']['mid']=$params['mid'];
	$params['type']=2;
	$return['params']['type']=2;
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getslice('core_credit_log',$params,array($pindex,$psize),$total,array(),'','id desc');
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'type','title'=>'积分类型','type'=>'radio','options'=>'types'),
			array('name'=>'is_add','title'=>'日志类型','type'=>'radio','options'=>'adds'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'plugin','title'=>'插件','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
	);
	exi($return);
}
if($_RQ['op']=='export2'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0,'type'=>'api');
	$return['params']=array();
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(isset($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('core_member_cash',$params,array(),'','id desc');
	$listhe=array();
	if($list){
		foreach($list as $item){
			$item['member']=model('core/core')->member_show($item['mid']);
			$item['nickname']=$item['member']['nickname'];
			$item['mobile']=$item['member']['mobile'];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$fans=pdo_get('core_fans',array('mid'=>$item['mid']),array('wxgid'));
			if($item['member']['from_os']==1){
				$item['apptitle']=pdo_getcolumn('core_account_wxapp',array('id'=>$fans['wxgid']),'title');
				$item['apptype']='小程序';
			}else{
				$item['apptitle']=pdo_getcolumn('core_account_wechat',array('id'=>$fans['wxgid']),'title');
				$item['apptype']='公众号';
			}
			if(!$listhe[$item['bankcard']]){
				$listhe[$item['bankcard']]=$item;
			}else{
				$listhe[$item['bankcard']]['money'] +=$item['money'];
				$listhe[$item['bankcard']]['service_money'] +=$item['service_money'];
				$listhe[$item['bankcard']]['cash_money'] +=$item['cash_money'];
			}
		}
	}
	$header=array(
		'mid'=>'会员ID',
		'nickname'=>'会员昵称',
		'mobile'=>'会员手机号',
		'money'=>'提现金额',
		'service_money'=>'提现手续费',
		'cash_money'=>'预计到账金额',
		'createtime'=>'申请时间',
	);
	model('core/tools')->export2excel($header,$listhe,'提现数据');
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']=array();
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(isset($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}	
	$list=pdo_getall('core_member_cash',$params,$fields);
	foreach($list as &$item){
			$item['member']=model('core/core')->member_show($item['mid']);
			$item['nickname']=$item['member']['nickname'];
			$item['mobile']=$item['member']['mobile'];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
	}
	$header=array(
		'mid'=>'会员ID',
		'nickname'=>'会员昵称',
		'mobile'=>'会员手机号',
		'money'=>'提现金额',
		'service_money'=>'提现手续费',
		'cash_money'=>'预计到账金额',
		'createtime'=>'申请时间',
	);
	model('core/tools')->export2excel($header,$list,'提现数据');
}